# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgbase=shiboken
pkgname=('python2-shiboken' 'python-shiboken' 'shiboken')
_pkgname=Shiboken
pkgver=1.2.4
_pyver=3.13
pkgrel=13
arch=('x86_64')
license=('LGPL')
url='https://github.com/pyside/Shiboken/tags'
depends=('libicu64')
makedepends=('cmake' 'python2' 'python' 'qt4' 'libxslt' 'openssl'
             'python-distutils-extra')
source=("$pkgbase-$pkgver.tar.gz::https://github.com/PySide/Shiboken/archive/$pkgver.tar.gz"
        'support-new-python.diff')
sha512sums=('daa3fadf3daffaec52f199c0285a37431a4b6b0d450a43a035f49e5505a35b666a1cb0b334c7267af7530841dadbf0b97296812141c93de3b7cd07c7d9016a2a'
            'fe42b2cc3792efd10d55caa9c34d74f8c06b1bca94d6d3a4b96c1558dc8a2f45841987e39d292b003ce05797cadb6f5dbfb96731a4f46f783e5dc252d3f240f3')

prepare() {
  cd "$_pkgname-$pkgver"

  patch -p1 -i ../support-new-python.diff
}

build() {
  cd "$_pkgname-$pkgver"

  mkdir -p build-py2 && cd build-py2

  cmake ../ -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_TESTS=OFF -DPYTHON_EXECUTABLE=/usr/bin/python2 \
    -DPYTHON_LIBRARY=/usr/lib/libpython2.7.so \
    -DPYTHON_INCLUDE_DIR=/usr/include/python2.7 -DQT_QMAKE_EXECUTABLE=qmake-qt4

  make -j1

  cd "$srcdir/$_pkgname-$pkgver"

  sed -i 's|type->tp_print = &SbkEnumObject_print;||g' libshiboken/sbkenum.cpp
  mkdir -p build-py3 && cd build-py3

  cmake ../ -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_TESTS=OFF -DUSE_PYTHON3=yes -DQT_QMAKE_EXECUTABLE=qmake-qt4 \
    -DUSE_PYTHON_VERSION=3 -DPYTHON_EXECUTABLE=/usr/bin/python3 \
    -DPYTHON3_INCLUDE_DIR="/usr/include/python$_pyver" \
    -DPYTHON3_LIBRARY="/usr/lib/python$_pyver" \
    -DPYTHON_INCLUDE_DIR="/usr/include/python$_pyver" \
    -DPYTHON_LIBRARY="/usr/lib/python$_pyver"

  make -j1
}

package_shiboken() {
  pkgdesc="CPython bindings generator for C++ libraries"
  depends=('python' 'qt4' 'libxslt')
  optdepends=("python2-shiboken: for compilation against python2"
              "python-shiboken: for compilation against python")

  # Header files/ /usr/bin/shiboke, pkgconfig, man page
  cd "$_pkgname-$pkgver/build-py3"
  make -j1 DESTDIR="$pkgdir" install

  cd "$srcdir/$_pkgname-$pkgver/build-py2/data"
  install -Dm 644 ShibokenConfig-python2.7.cmake \
    "$pkgdir/usr/lib/cmake/$_pkgname-$pkgver/"
  install -Dm 644 shiboken.pc "$pkgdir/usr/lib/pkgconfig/shiboken-py2.pc"

  rm -rf "$pkgdir/usr/lib/python"*
  rm -rf "$pkgdir/usr/lib/libshiboken"*
  rm -rf "$pkgdir/usr/lib/pkgconfig/"
  rm "$pkgdir"/usr/lib/cmake/$_pkgname-$pkgver/ShibokenConfig*python*.cmake
}

package_python2-shiboken() {
  pkgdesc="Support library for Python2 bindings"
  depends=("qt4>=4.8" "libxslt" "python2" "shiboken")

  cd "$_pkgname-$pkgver/build-py2"

  make -j1 DESTDIR="$pkgdir" install

  cd "$srcdir/$_pkgname-$pkgver/build-py2/data"
  install -Dm 644 ShibokenConfig-python2.7.cmake \
    "$pkgdir/usr/lib/cmake/$_pkgname-$pkgver/"
  mv "$pkgdir"/usr/lib/pkgconfig/shiboken{,-py2}.pc

  rm -rf "$pkgdir"/usr/{include,bin,share}
  rm "$pkgdir/usr/lib/cmake/$_pkgname-$pkgver/ShibokenConfigVersion.cmake"
  rm "$pkgdir/usr/lib/cmake/$_pkgname-$pkgver/ShibokenConfig.cmake"
}

package_python-shiboken() {
  pkgdesc="Support library for Python bindings"
  depends=("qt4>=4.8" "libxslt" "python" "shiboken")

  cd "$_pkgname-$pkgver/build-py3"

  make -j1 DESTDIR="$pkgdir" install

  rm -rf "$pkgdir"/usr/{include,bin,share}
  rm "$pkgdir/usr/lib/cmake/$_pkgname-$pkgver/ShibokenConfigVersion.cmake"
  rm "$pkgdir/usr/lib/cmake/$_pkgname-$pkgver/ShibokenConfig.cmake"
}

